package com.hmdp.controller;


import com.hmdp.dto.Result;
import com.hmdp.dto.UserDTO;
import com.hmdp.service.IFollowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 虎哥
 * @since 2021-12-22
 */
@Api(tags = "关注相关接口")
@RestController
@RequestMapping("/follow")
@RequiredArgsConstructor
public class FollowController {

    private final IFollowService followService;

    @ApiOperation("关注或取消关注")
    @PutMapping("/{id}/{isFollow}")
    public Result follow(@PathVariable("id") Long followUserId, @PathVariable("isFollow") Boolean isFollow) {
        followService.followOrUnfollow(followUserId, isFollow);
        return Result.ok();
    }

    @ApiOperation("判断当前用户是否关注了该用户")
    @GetMapping("/or/not/{id}")
    public Result isFollow(@PathVariable("id") Long followUserId) {
        return Result.ok(followService.isFollow(followUserId));
    }

    @ApiOperation("获取共同关注用户列表")
    @GetMapping("/common/{id}")
    public Result followCommons(@PathVariable("id") Long id) {
        List<UserDTO> userDTOS = followService.followCommons(id);
        return Result.ok(userDTOS);
    }

}
